package org.balabala.os.management;

import org.balabala.os.client.MinIOClient;
import org.balabala.os.conf.ObjectStorageConf;
import org.balabala.os.exception.ClientInitRepeatException;
import org.balabala.os.exception.ClientNotInitException;

public class MinIOClientManager extends ObjectStorageClientManager {
    private static volatile MinIOClient client;

    private static volatile boolean isInit = false;

    private static volatile ObjectStorageConf osc;

    // 构造方法私有化，不能私自生成ObjectStorageManager类
    private MinIOClientManager() {}

    // 能且仅能初始化一次
    public static void init(ObjectStorageConf conf) throws ClientInitRepeatException {
        if (isInit) return;
        synchronized (MinIOClientManager.class) {
            client = MinIOClient.build(conf);
            isInit = true;
        }
    }

    public static MinIOClient getClient() throws ClientNotInitException {
        if (isInit) return client;
        // 未初始化直接异常
        throw new ClientNotInitException("Client not init!\n");
    }
}
